import modelEnhance from '@/utils/modelEnhance';
import { register, getVerifyCode, } from '../service';

export default modelEnhance({
  namespace: 'register',

  state: {
    status: undefined,
    code: '',
  },

  effects: {
    *submit({ payload }, { call, put }) {
      console.log(payload)
      const response = yield call(register, payload);
      yield put({
        type: 'registerHandle',
        payload: response,
      });
    },
    *getverifycode({ payload }, { call, put }) {
      console.log(payload)
      const response = yield call(getVerifyCode, payload);
      if(response.code === 200){
        console.log(response);
        yield put({
          type: 'verifycodeHandle',
          payload: response,
        });
      }
    },
  },

  reducers: {
    verifycodeHandle(state, { payload }) {
      return {
        ...state,
        code: payload.code,
      }
    },
    registerHandle(state, { payload }) {
      return {
        ...state,
        status: payload.status,
      };
    },
  },
});